using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Sysgeprava.Entities;

namespace Sysgeprava.Repository.Mapping
{
    public class ESTABLOMap : EntityTypeConfiguration<ESTABLO>
    {
        public ESTABLOMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Codigo)
                .IsRequired()
                .HasMaxLength(10);

            this.Property(t => t.Nombre)
                .IsRequired()
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("ESTABLO");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.Codigo).HasColumnName("Codigo");
            this.Property(t => t.Nombre).HasColumnName("Nombre");
            this.Property(t => t.CantBovinos).HasColumnName("CantBovinos");
            this.Property(t => t.IdTipEstablo).HasColumnName("IdTipEstablo");
            this.Property(t => t.IdFinca).HasColumnName("IdFinca");

            // Relationships
            this.HasOptional(t => t.FINCA)
                .WithMany(t => t.ESTABLOes)
                .HasForeignKey(d => d.IdFinca);
            this.HasOptional(t => t.TIP_ESTABLO)
                .WithMany(t => t.ESTABLOes)
                .HasForeignKey(d => d.IdTipEstablo);

        }
    }
}
